var nextFrame;
if (gg.runAt.browser) {
    nextFrame = window.requestAnimationFrame
            || window.webkitRequestAnimationFrame
            || window.mozRequestAnimationFrame
            || window.oRequestAnimationFrame
            || window.msRequestAnimationFrame;
} else if (gg.runAt.server) {
    nextFrame = process.nextTick;
}
else {
    nextFrame = function(callback) {
        return window.setTimeout(function() {
            return callback();
        }, 1000);
    };
}
/*
 if (cc && cc.Director) {
 cc.Director.getInstance().getScheduler().scheduleUpdateForTarget(this, 0, false);
 }
 if (cc && cc.Director) {
 cc.Director.getInstance().getScheduler().unscheduleUpdateForTarget(this);
 }
 */
var BaseClass = gg.module('BaseObject');

module.exports = gg.createClass({
    attrs: {
    },
    methods: {
        _lastTime: 0,
        _start: false,
        start: function() {
            if (this._start === true) {
                return;
            }
            this._lastTime = Date.now();
            this._start = true;
            var callback = _.bind(function() {
                if (!this._start) {
                    return;
                }
                var now = Date.now();
                var dt = now - this._lastTime;
                this._lastTime = now;
                console.log(dt);
                this.update(dt);
                nextFrame(callback);
            }, this);
            callback();
        },
        stop: function() {
            this._start = false;
        },
        update: function(dt) {
            this.get('logic').update(dt);
        }
    },
    events: {}
}, BaseClass, []);

/** @fileend */

//unittest
UnitTest.add('Application',
        function() {
            this.test(true, 'OK');
        }
);
